﻿using Abp.AutoMapper;
using Abp.Runtime.Validation;
using NetCore.CustomAttributes;
using NetCore.Dtos;
using NetCore.Entities.Needs;
using NetCore.Enums;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace NetCore.Needs.Dtos
{
    /// <summary>
    /// 需求Dto
    /// </summary>
    [AutoMap(typeof(Need)), Description("需求")]
    public class NeedDto : BaseDto
    {
        public NeedDto()
        {
            Attachments = new List<NeedAttachmentDto>();
        }
        /// <summary>
        /// 性别
        /// </summary>
        [Description("性别"), Required]
        public Sex Sex { get; set; }
        /// <summary>
        /// 手机
        /// </summary>
        [Description("手机"), Required, Regex(Regxes.MobilePhone)]
        public string Phone { get; set; }
        /// <summary>
        /// QQ
        /// </summary>
        [Description("QQ")]
        public string QNumber { get; set; }
        /// <summary>
        /// 邮箱
        /// </summary>
        [Description("邮箱"), Regex(Regxes.Email)]
        public string Email { get; set; }
        /// <summary>
        /// 需求明细
        /// </summary>
        [Description("需求明细"), Required]
        public string Requirements { get; set; }
        /// <summary>
        /// 附件字符串
        /// </summary>
        [Description("附件")]
        public string AttachementsString { get; set; }
        /// <summary>
        /// 附件
        /// </summary>
        [Description("附件"), NotSet]
        public List<NeedAttachmentDto> Attachments { get; set; }



        public override void AddValidationErrors(CustomValidationContext context)
        {
            //if (!Phone.Validate())
            //{
            //    context.Results.Add(new ValidationResult("请输入正确的电话号码!"));
            //}
            //AddFiles();//验证完毕之后，初始化Files集合 此处仅为程序使用提供初始化服务，由前端控制上传个数验证
            //if (Files.Count(m => m.Name.HasValue()) > 20)
            //{
            //    context.Results.Add(new ValidationResult("批量上传文件最多20个"));
            //}
        }
    }
}
